const ROTATE_LINEARITY = 0.25;
const ROTATE_MAX_SPEED = 180;
const ROTATE_DECELERATION = 180;

const PITCH_LINEARITY = 0.1;
const PITCH_MAX_SPEED = 180;
const PITCH_DECELERATION = 360;

export function getRotateInertia(flingDiff: number, flingDuration: number) {
    if (flingDiff === 0 || flingDuration === 0) return;
    const sign = flingDiff < 0 ? -1 : 1;
    let speed = Math.abs(flingDiff * (ROTATE_LINEARITY / flingDuration));
    if (speed > ROTATE_MAX_SPEED) {
        speed = ROTATE_MAX_SPEED;
    }
    const duration = speed / (ROTATE_DECELERATION * ROTATE_LINEARITY);
    const offset = sign * speed * (duration / 2);
    return { duration, offset };
}

export function getPitchInertia(flingDiff: number, flingDuration: number) {
    if (flingDiff === 0 || flingDuration === 0) return;
    const sign = flingDiff < 0 ? -1 : 1;
    let speed = Math.abs(flingDiff * (PITCH_LINEARITY / flingDuration));
    if (speed > PITCH_MAX_SPEED) {
        speed = PITCH_MAX_SPEED;
    }
    const duration = speed / (PITCH_DECELERATION * PITCH_LINEARITY);
    const offset = sign * speed * (duration / 2);
    return { duration, offset };
}
